<?PHP
include "../../mainfile.php";
include XOOPS_ROOT_PATH.'/header.php';
include_once(XOOPS_ROOT_PATH."/class/module.textsanitizer.php");
require_once XOOPS_ROOT_PATH."/class/xoopsmailer.php";



$myts =& MyTextSanitizer::getInstance();

if($_SESSION['use_ssl'] == 'true' && 'on' != $_SERVER['HTTPS']){// do not display form b/c it is not secure and it should be
	$_SESSION['errorMessage'] = "WARNING! PLEDGE NOT SUBMITTED. We could not verify that you have a secure connection to the server.";
	$page = $_POST['pageNumber'] - 1;
	header("Location:index.php?pageNumber=$page");
}else if($_POST['pageNumber'] == '2'){
			
			unset($_SESSION['errorMessage']);///Clear out existing missing field warnings 
			
			//#######################################
			//GET STUFF FROM PAGE ONE OF PLEDGE FORM
			//#######################################
			$_SESSION['Page1_missing'] = array();
			$page_one_requiredFields = array("pledgeType","pledgeLevel","installments");
			$page_one_error_messages = array("&#8226; Please select your Pledge Type.<br />","&#8226; Please select an amount for your Pledge Level.<br />","&#8226; Please specify number of installments for your pledge.<br />");
			
			
			$_SESSION['pledgeType'] = $_POST['pledgeType'];
			$_SESSION['pledgeLevelOther'] = $myts->makeTboxData4Show(str_replace("$", "",$_POST['pledgeLevelOther']));
			$_SESSION['installments'] = $_POST['installments'];
			$_SESSION['numInstallments'] = $_POST['numInstallments'];
			unset($_SESSION['premiumsRadio']);//unset from last submission of form...  incase user has changed gift selection
			$_SESSION['premiumsRadio'] = $_POST['premiumsRadio'];
			$_SESSION['noPremiums'] = $_POST['noPremiums'];
			
			//if no premiums were selected and the check box wasn;t checked - set to no gifts
			if(!$_POST['premiumsRadio'] && !$_POST['noPremiums']){
				$_SESSION['noPremiums'] = 'true';
			}
			
			
			//Clear out Slected gifts if user checks the "No gifts Box"
			if($_SESSION['noPremiums'] == 'true'){
				unset($_SESSION['premiumsRadio']);
			}
			
			if($_SESSION['pledgeType'] == ""){
				$_SESSION['Page1_missing'][] = 'pledgeType';//tRIGGER MISSING FIELD WARNING
			}
			
			
			
			//Make Number of installments field = "" if pledge is all paid at once
			if($_SESSION['numInstallments'] != ""){
				$_SESSION['installments'] = 'yes';
			}elseif($_SESSION['installments'] == 'no'){
				unset($_SESSION['numInstallments']);
			}else if($_SESSION['installments'] == 'yes' && $_SESSION['numInstallments'] == ""){
				$_SESSION['Page1_missing'][] = 'installments';//tRIGGER MISSING FIELD WARNING
			}
			
			
			
			
			
			//make sure "other" text field has data if "other" radio button is checked
			if($_POST['pledgeLevel'] == 'other' && $_POST['pledgeLevelOther'] == ""){
				$_SESSION['Page1_missing'][] = 'pledgeLevel';//tRIGGER MISSING FIELD WARNING
				$_SESSION['pledgeLevel'] = 'other';
			}elseif($_POST['pledgeLevel'] == ""){
				$_SESSION['Page1_missing'][] = 'pledgeLevel';//tRIGGER MISSING FIELD WARNING
			}else{
				$_SESSION['pledgeLevel'] = $_POST['pledgeLevel'];
			}
			
			
			
			//###########################################################################################################
			//so people with out javascript will have their pledge levels remembered when going back to the previous page
			if(!$_SESSION['Last_pledgeLevel']){
				$_SESSION['Last_pledgeLevel'] = $_SESSION['pledgeLevel'];
			}else if($_SESSION['Last_pledgeLevel'] != $_SESSION['pledgeLevel']){//user has changed level
				$_SESSION['Last_pledgeLevel'] = $_SESSION['pledgeLevel'];
				
				if($_SESSION['pledgeLevel'] != 'other'){
					$_SESSION['pledgeLevelOther'] = "";
				}
			}
			
				if($_SESSION['Last_pledgeLevelOther'] == ""){
					$_SESSION['Last_status'] = 'empty';
				}else{
					$_SESSION['Last_status'] = 'not_empty';
				}
			
				if($_SESSION['pledgeLevelOther'] == ""){
					$_SESSION['this_status'] = 'empty';
				}else{
					$_SESSION['this_status'] = 'not_empty';
				}
			
				if($_SESSION['Last_status'] == 'empty' && $_SESSION['this_status'] == 'not_empty'){
					$_SESSION['pledgeLevel'] = 'other';
				}
			
				if(!$_SESSION['Last_pledgeLevelOther']){
					$_SESSION['Last_pledgeLevelOther'] = $_SESSION['pledgeLevelOther'];
				}else if($_SESSION['Last_pledgeLevelOther'] != $_SESSION['pledgeLevelOther']){
				
					$_SESSION['Last_pledgeLevelOther'] = $_SESSION['pledgeLevelOther'];
				}
			
			//###########################################################################################################
			
			
			
			//Check for required fields
			for ($i = 0; $i < count($page_one_requiredFields); $i++) {
				if(in_array($page_one_requiredFields[$i],$_SESSION['Page1_missing'])){
					$_SESSION['errorMessage'] = $_SESSION['errorMessage'] . $page_one_error_messages[$i];
				}
			}
			
			
			//print_r($_SESSION['Page1_missing']);
			
			
			//SEND TO APPROPRIATE LOCATION
			if(count($_SESSION['Page1_missing']) > '0'){
				$_SESSION['pageOneComplete'] = "";
				header("Location:index.php?pageNumber=1");
			}elseif($_SESSION['change'] == 'true'){
				$_SESSION['pageOneComplete'] = 'true';
				unset($_SESSION['change']);
				header("Location:index.php?pageNumber=3");
			}else{
				$_SESSION['pageOneComplete'] = 'true';
				header("Location:index.php?pageNumber=2");
				unset($_SESSION['Page1_missing']);
			}



}else if ($_POST['pageNumber'] == '3'){
			//##########################################################################################################
			//##########################################################################################################
			//##########################################################################################################
			
			
			//Get necessary class include
			require_once ("Date.php");

			//uncomment this out if pear Date is not installed
			//include_once 'include/Date.php';
			require_once 'include/Validate.php';
			require_once 'include/CreditCard.php';
			$noYes = array('NO', 'YES');
			
			//#######################################
			//GET STUFF FROM PAGE TWO OF PLEDGE FORM
			//#######################################
			$_SESSION['Page2_missing'] = array();
			$_SESSION['errorMessage'] = "";
			$page_two_requiredFields = array("firstName","lastName","address","city","state","zipCode","emailAddress","paymentType","ccName","ccNumber","ccExpirationMonth","ccExpirationYear","ccCID");
			$page_two_error_messages = array("&#8226; Please enter your First Name.<br />","&#8226; Please enter your Last Name.<br />","&#8226; Please enter your Address.<br />","&#8226; Please enter your City.<br />","&#8226; Please enter your State.<br />","&#8226; Please enter your Zip Code.<br />","&#8226; Please enter a valid Email Address.<br />","&#8226; Please select a Method of Payment.<br />","&#8226; Please enter your name as it appears on your Credit Card.<br />","&#8226; Please enter a valid Credit Card Number.<br />","&#8226; Please select a valid Credit Card Expiration Date.<br />","&#8226; Please enter a valid Credit Card Security Code.<br />","&#8226; Please enter a valid Credit Card Securiy Code.<br />");
			
			//allow error check to ignore credit card security code if payment type is "Bill Me" or "AE"
			if($_POST['paymentType'] == 'American Express' || $_POST['paymentType'] == 'Bill Me'){
				$_POST['ccCID'] = " ";
			}
			
			
			
			
			//validate credit card numbers and security code
			 if($_POST['paymentType'] == 'Bill Me'){
				$_POST['ccName'] = " ";
				$_POST['ccNumber'] = " ";
			}else{
				$_POST['ccName'] = $myts->makeTboxData4Show($_POST['ccName']);
				$_POST['ccNumber'] = $myts->makeTboxData4Show($_POST['ccNumber']);			
				$_POST['ccCID'] = $myts->makeTboxData4Show($_POST['ccCID']);
			
				//See if we have a valid number for the card type
				if($noYes[Validate_Finance_CreditCard::type($_POST['ccNumber'], $_POST['paymentType'])] == 'NO'){
					$_POST['ccNumber'] = "";
				}
				
				//Check to macke sure card security ID is valid
				if($_POST['paymentType'] != 'American Express' && $noYes[Validate_Finance_CreditCard::cvv($_POST['ccCID'], $_POST['paymentType'])] == 'NO' && $_POST['paymentType'] != 'American Express' && $_POST['paymentType'] != 'Bill Me'){
					$_POST['ccCID'] = "";
				}
			
			
				//Validate Credit Card Expiration Date
				$date = '01'.$_POST['ccExpirationMonth'].$_POST['ccExpirationYear'];
				$minDate = date("Y").date("m").'01';
				$dateObjects = array(array($date, 'format'=>'%d%m%Y', 'min' => new Date($minDate)));
				foreach ($dateObjects as $data){
					$date = array_shift($data);
					foreach ($data as $key=>$val) {
					}
		
					if($noYes[Validate::date($date, $data)] == 'NO'){
						$_POST['ccExpirationMonth'] = "";
					}
				}			
			
			
			}//end else
			
			
			//if No Payment Type was selected.. Trigger warning
			if(!isset($_POST['paymentType'])){
				$_POST['paymentType'] = "";
			}
			
			
			
			//Validate Email Addy
			if($noYes[Validate::email($_POST['emailAddress'], true)] == 'NO'){
				$_POST['emailAddress'] = "";
				unset($_SESSION['emailAddress']);
			}
			//echo $noYes[Validate::email($_POST['emailAddress'], true)];

		
			
			//Do error checking and convert post variables into session vars. (Yes if I had only done it this way for page 1- holy hindsight batman.)
			$form_fields = array_keys($_POST);
			for ($i = 0; $i < (sizeof($form_fields)); $i++) {
					$thisField = $form_fields[$i];
					$thisValue = $_POST[$thisField];
					if(in_array($thisField, $page_two_requiredFields) && $thisValue == ""){
						$_SESSION['Page2_missing'][] = $thisField;
						$_SESSION['errorMessage'] = $_SESSION['errorMessage'] . $page_two_error_messages[(array_search ($thisField, $page_two_requiredFields))];
						//echo "$thisField: $thisValue<BR>";
					
					}
						$_SESSION["$thisField"] = $myts->makeTboxData4Show($thisValue);
			}			


			//GO TO APPROPRIATE PLACE
			 if(count($_SESSION['Page2_missing']) > '0'){
				$_SESSION['pageTwoComplete'] = "";
				header("Location:index.php?pageNumber=2");
			}else if($_SESSION['change'] == 'true'){
				$_SESSION['pageTwoComplete'] = 'true';
				unset($_SESSION['change']);
				header("Location:index.php?pageNumber=3");
			}else{
				$_SESSION['pageTwoComplete'] = 'true';
				header("Location:index.php?pageNumber=3");
			}
			 
			
			
			
			
			
}else if ($_POST['pageNumber'] == '4'){//Send email and display Thank You page...





	//insert user into recent pledges database of they have requested to be listed
	if($_SESSION['recentPledges']=='yes'){
		if($_SESSION['pledgeLevel'] == 'other'){
			$amount = $_SESSION['pledgeLevelOther'];
		}else{
			$amount = $_SESSION['pledgeLevel'];
		}
		$name = $_SESSION['firstName']." ".$_SESSION['lastName'];
		$date = mktime(0,0,0,date("m"),date("d"),date("Y")); 
		$xoopsDB->query("INSERT INTO " . $xoopsDB->prefix('pledge_recent') . " values ('0','$name','$amount','$date')");
	}



$params['sendmail_path'] = '/usr/lib/sendmail'; // PATH TO SENDMAIL
setlocale(LC_MONETARY, 'en_US');//DEFAULT CURRENCY

//Figure out what to send in eemail
	if($_SESSION['pledgeLevel'] == 'other'){
		$amount = money_format('%.0n', $_SESSION['pledgeLevelOther']);
	}else{
		$amount = money_format('%.0n', $_SESSION['pledgeLevel']);
	}
	
	//THank You gift $_SESSION['premiumsRadio']
	if($_SESSION['noPremiums'] == 'true'){
		$gifts = " -No gifts please.";
	}else{
		$gifts = "";
		for ($i = 0; $i < count($_SESSION['premiumsRadio']); $i++) {
		
			//Kick me in the Jimmy
			for ($r = 0; $r < count($_SESSION['premiums']); $r++) {
				if($_SESSION['premiumsRadio'][$i] == $_SESSION['premiums'][$r]['itemID']){
				$pointer = $r;
				break;				
				}
			}
			//$pointer = array_search($_SESSION['premiumsRadio'][$i], $_SESSION['premiums']);
			$gifts = $gifts . " -".$_SESSION['premiums'][$pointer]['description'] . "\n"; // 
		}
	
	}
	
	
	//SPOUSE PARTNER INFO
	if($_SESSION['spouseFirstName'] != "" || $_SESSION['spouseLastName'] != ""){
		$spouse = "Spouse/Partner First Name: ".$_SESSION['spouseFirstName']."\nSpouse/Partner Last Name: ".$_SESSION['spouseLastName']."\n";
	}else{
		$spouse="";
	}
	
	
	//Address two
	if($_SESSION['address2'] != ""){
		$addy2 = "Address 2: ".$_SESSION['address2']."\n";
	}else{
		$addy2 = "";
	}
	
	//HOME PHONE
	if($_SESSION['homePhone'] == ""){
		$homePhone = "";
	}else{
		$homePhone = "\nHome Phone: ".$_SESSION['homePhone'];
	}

	//WORK PHONE
	if($_SESSION['workPhone'] != ""){
		$workPhone = "Work Phone: ".$_SESSION['workPhone']."\n";
	}else{
		$workPhone = "";
	}

	//Comments
	if($_SESSION['comments'] != ""){
		$comments = "COMMENTS: \n".$_SESSION['comments'] . "\n";
	}else{
		$comments = "";
	}


	//NUmber of installments
			if($_SESSION['installments'] == 'no'){
				$numInstallments = "Pay all at once.";
			}else{
				$numInstallments = $_SESSION['numInstallments'];
			}		



	//Payment info
	if($_SESSION['paymentType'] == 'Bill Me'){
		$paymentInfo = "Method of payment: Bill Me\nInstallments: $numInstallments" ;
	}else{
		$paymentInfo = "Method of payment: ".$_SESSION['paymentType']."\nName as it appears on card: ".$_SESSION['ccName']."\nCredit Card Number: ".$_SESSION['ccNumber']."\nExpiration Date: ".$_SESSION['ccExpirationMonth']."/".$_SESSION['ccExpirationYear']."\nCredit Card Security Code: ".$_SESSION['ccCID']."\n";
	}

	
   ## require 'gpg_encrypt.php' to create
   ## the gpg_encrypt() function
   require_once('include/gpg_encrypt.php');
   require_once('Mail.php');



//Compile message with sensitive billing info
$body="\n".date("m/d/Y")."\n".date("h:i:s A")."\n\n
PLEDGE TYPE: ".$_SESSION['pledgeType']."\n
PLEDGE LEVEL: $amount\n
THANK YOU GIFT:\n$gifts

PERSONAL INFORMATION:\nFirst Name: ".$_SESSION['firstName']."\nLast Name: ".$_SESSION['lastName']."\n$spouse"."Address: ".$_SESSION['address']."\n$addy2"."City: ".$_SESSION['city']."\nState: ".$_SESSION['state']."\nZip: ".$_SESSION['zipCode']."\nCountry: ".$_SESSION['country']."$homePhone\n$workPhone"."Email Address: ".$_SESSION['emailAddress']."
Receive Email Newsletter: ".$_SESSION['emailOptIn']."
Receive Expiration Notice: ".$_SESSION['Renewal_Notice_OptIn']."
Read name on air: ".$_SESSION['readName']."\n
$comments
PAYMENT INFORMATION:
$paymentInfo";


if($_SESSION['gpg_encrypt_info_4_billing'] == 'true'){//if GPG ENCRYPTION IS ENABLED IN WEB PLEDGE ADMIN
		   ## encrypt $message to key ID 0x123456
		   ## using /usr/local/bin/gpg
		   ## and a keyring at /home/www/.gnupg
		   $gpg = gpg_encrypt("$body", '/usr/bin/gpg' , '/home/gpg/.gnupg', $_SESSION['billing_recipient_Email']);
		   ## $gpg is an array containing
		   ## $gpg[0] encrypted output (STDOUT)
		   ## $gpg[1] warnings and notices (STDERR)
		   ## $gpg[2] exit status from gpg
		
		   ## test gpg's exit status
		   if("$gpg[2]" == '0') {
			  ## if the gpg command returned zero
			  ## then mail out the message
			  ## to "email@address.com"
			  ## with a subject: encrypted message
	
			
			$xoopsMailer =& getMailer();
			$xoopsMailer->useMail(); 
			$xoopsMailer->setTemplateDir(XOOPS_ROOT_PATH.'/modules/pledge/templates');
			$xoopsMailer->setTemplate("mailRecipient.tpl");
			$xoopsMailer->setToEmails($_SESSION['billing_recipient_Email']);
			$xoopsMailer->setFromEmail('webpledge@'.$_SESSION['stationLetters'].'.com');
			$xoopsMailer->setFromName('webpledge'); 
			$xoopsMailer->setSubject('On-Line Web Pledge From '.$_SESSION['stationLetters']);
			$xoopsMailer->assign("MESSAGE", $gpg[0]); 
			$xoopsMailer->send();
			
			
			  
		   } else {
			  ## if the gpg command returned non-zero
			  ## then display gpg's diagnostic output
			  $_SESSION['errorMessage'] = $gpg[1];
			  header("Location:index.php?pageNumber=3");
		   }
   
   
}else{
	//SEND TO BILLING PERSON WITHOUT ENRCYPTION - BAD IDEA YO

			$xoopsMailer =& getMailer();
			$xoopsMailer->useMail(); 
			$xoopsMailer->setTemplateDir(XOOPS_ROOT_PATH.'/modules/pledge/templates');
			$xoopsMailer->setTemplate("mailRecipient.tpl");
			$xoopsMailer->setToEmails($_SESSION['billing_recipient_Email']);
			$xoopsMailer->setFromEmail('webpledge@'.$_SESSION['stationLetters'].'.com');
			$xoopsMailer->setFromName('webpledge'); 
			$xoopsMailer->setSubject('On-Line Web Pledge From '.$_SESSION['stationLetters']);
			$xoopsMailer->assign("MESSAGE", $body); 
			$xoopsMailer->send();
	
	
	
}  
   
   
   
//Compile message with non-sensitive billing info
$body1="\n".date("m/d/Y")."\n".date("h:i:s A")."\n\n
PLEDGE TYPE: ".$_SESSION['pledgeType']."\n
PLEDGE LEVEL: $amount\n
THANK YOU GIFT:\n$gifts

PERSONAL INFORMATION:\nFirst Name: ".$_SESSION['firstName']."\nLast Name: ".$_SESSION['lastName']."\n$spouse"."Address: ".$_SESSION['address']."\n$addy2"."City: ".$_SESSION['city']."\nState: ".$_SESSION['state']."\nZip: ".$_SESSION['zipCode']."\nCountry: ".$_SESSION['country']."$homePhone\n$workPhone"."Email Address: ".$_SESSION['emailAddress']."
Receive Email Newsletter: ".$_SESSION['emailOptIn']."
Receive Expiration Notice: ".$_SESSION['Renewal_Notice_OptIn']."
Read name on air: ".$_SESSION['readName']."
List with recent pledges: ".$_SESSION['recentPledges']."\n
$comments";
			   
   
   
   
   
   
if($_SESSION['gpg_encrypt_info_4_non_billing'] == 'true'){
			
			   ## encrypt $message to key ID 0x123456
			   ## using /usr/local/bin/gpg
			   ## and a keyring at /home/www/.gnupg
			   $gpg = gpg_encrypt("$body1", '/usr/bin/gpg' , '/home/gpg/.gnupg', $_SESSION['non_billing_recipients']);//$_SESSION['non_billing_recipients']
			   ## $gpg is an array containing
			   ## $gpg[0] encrypted output (STDOUT)
			   ## $gpg[1] warnings and notices (STDERR)
			   ## $gpg[2] exit status from gpg
			
			   ## test gpg's exit status
			   if("$gpg[2]" == '0') {
				  ## if the gpg command returned zero
				  ## then mail out the message
				  ## to "email@address.com"
				  ## with a subject: encrypted message
				  
					//SEND TO NON BILLING PEOPLE 
					/* $recipients = $_SESSION['non_billing_recipients'];
					$headers['From'] = 'webpledge@'.$_SESSION['stationLetters'].'.com';
					$headers['To'] = $_SESSION['non_billing_recipients'];
					$headers['Subject'] = 'On-Line Web Pledge From '.$_SESSION['stationLetters'];
					
					// Create the mail object using the Mail::factory method
					$mail_object =& Mail::factory('sendmail', $params);
					$mail_object->send($recipients, $headers, $gpg[0]);
					unset($headers,$mail_object);   */
					
					$xoopsMailer =& getMailer();
					$xoopsMailer->useMail(); 
					$xoopsMailer->setTemplateDir(XOOPS_ROOT_PATH.'/modules/pledge/templates');
					$xoopsMailer->setTemplate("mailRecipient.tpl");
					$xoopsMailer->setToEmails($_SESSION['non_billing_recipients']);
					$xoopsMailer->setFromEmail('webpledge@'.$_SESSION['stationLetters'].'.com');
					$xoopsMailer->setFromName('webpledge'); 
					$xoopsMailer->setSubject('On-Line Web Pledge From '.$_SESSION['stationLetters']);
					$xoopsMailer->assign("MESSAGE", $gpg[0]); 
					$xoopsMailer->send();
					
					
					
					
				  
			   } else {
				  ## if the gpg command returned non-zero
				  ## then display gpg's diagnostic output
				  $_SESSION['finished'] = 'false';
				  $_SESSION['errorMessage'] = $gpg[1];
				  header("Location:index.php?pageNumber=3");
			   }


}else{
					//SEND TO NON BILLING PEOPLE 
					/* $recipients = $_SESSION['non_billing_recipients'];
					$headers['From'] = 'webpledge@'.$_SESSION['stationLetters'].'.com';
					$headers['To'] = $_SESSION['non_billing_recipients'];
					$headers['Subject'] = 'On-Line Web Pledge From '.$_SESSION['stationLetters'];
					
					// Create the mail object using the Mail::factory method
					$mail_object =& Mail::factory('sendmail', $params);
					$mail_object->send($recipients, $headers, $body1);
					unset($headers,$mail_object);  */ 
					$xoopsMailer =& getMailer();
					$xoopsMailer->useMail(); 
					$xoopsMailer->setTemplateDir(XOOPS_ROOT_PATH.'/modules/pledge/templates');
					$xoopsMailer->setTemplate("mailRecipient.tpl");
					$xoopsMailer->setToEmails($_SESSION['non_billing_recipients']);
					$xoopsMailer->setFromEmail('webpledge@'.$_SESSION['stationLetters'].'.com');
					$xoopsMailer->setFromName('webpledge'); 
					$xoopsMailer->setSubject('On-Line Web Pledge From '.$_SESSION['stationLetters']);
					$xoopsMailer->assign("MESSAGE", $body1); 
					$xoopsMailer->send();


}


//SEND CONFIRMATION TO PERSON WHO MADE THE PLEDGE
$body1="\nThank you for your on-line contribution!  

This e-mail is to let you know that the ".$_SESSION['stationLetters']." membership office has received your pledge.

Your financial gift is tax deductible. You may use this page for your records. If you pledged $250 or more, ".$_SESSION['stationLetters']." will send you a notice in January ".(date("Y") +1)." for filing purposes.

If you have any questions about your membership, please contact ".$_SESSION['Billing_Recipient_Name']." in Membership Services at ".$_SESSION['Customer_Service_local_number'].$_SESSION['Customer_Service_toll_free_number']." or ".$_SESSION['Customer_Service_Email']."

".date("m/d/Y")."\n".date("h:i:s A")."\n\n
PLEDGE TYPE: ".$_SESSION['pledgeType']."\n
PLEDGE LEVEL: $amount\n
THANK YOU GIFT:\n$gifts
PERSONAL INFORMATION:\nFirst Name: ".$_SESSION['firstName']."\nLast Name: ".$_SESSION['lastName']."\n$spouse"."Address: ".$_SESSION['address']."\n$addy2"."City: ".$_SESSION['city']."\nState: ".$_SESSION['state']."\nZip: ".$_SESSION['zipCode']."\nCountry: ".$_SESSION['country']."$homePhone\n$workPhone"."Email Address: ".$_SESSION['emailAddress']."
Receive Email Newsletter: ".$_SESSION['emailOptIn']."
Receive Expiration Notice: ".$_SESSION['Renewal_Notice_OptIn']."
Read name on air: ".$_SESSION['readName']."
List with recent pledges: ".$_SESSION['recentPledges']."\n
$comments";

/* $recipients = $_SESSION['emailAddress'];
$headers['From'] = $_SESSION['Customer_Service_Email'];
//$headers['From'] = 'memberservices@'.$_SESSION['stationLetters'].'.com';
$headers['To'] = $_SESSION['emailAddress'];
$headers['Subject'] = 'Thank you for your pledge';


// Create the mail object using the Mail::factory method
$mail_object =& Mail::factory('sendmail', $params);
$mail_object->send($recipients, $headers, $body1); */

					$xoopsMailer =& getMailer();
					$xoopsMailer->useMail(); 
					$xoopsMailer->setTemplateDir(XOOPS_ROOT_PATH.'/modules/pledge/templates');
					$xoopsMailer->setTemplate("mailRecipient.tpl");
					$xoopsMailer->setToEmails($_SESSION['emailAddress']);
					$xoopsMailer->setFromEmail($_SESSION['Customer_Service_Email']);
					$xoopsMailer->setFromName(''); 
					$xoopsMailer->setSubject('Thank you for your membership pledge to ' . $_SESSION['stationLetters']);
					$xoopsMailer->assign("MESSAGE", $body1); 
					$xoopsMailer->send();




//SEND BACK TO INDEX>PHP TO DISPLAY THANK YOU PAGE
$_SESSION['finished'] = 'true';
header("Location:index.php?pageNumber=4");

}

?>